package com.jn.erp.web.api.course.controller;


import com.jn.erp.common.core.page.TableDataInfo;
import com.jn.erp.common.core.result.AjaxResult;
import com.jn.erp.security.controller.BaseWebAuthController;
import com.jn.erp.web.api.course.entity.THoliday;
import com.jn.erp.web.api.course.entity.dto.TCourseDto;
import com.jn.erp.web.api.course.entity.vo.TCourseOrderConfigVo;
import com.jn.erp.web.api.course.entity.vo.TCourseVo;
import com.jn.erp.web.api.course.entity.vo.THolidayVo;
import com.jn.erp.web.api.course.service.THolidayService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import org.springframework.stereotype.Controller;

import java.time.LocalDateTime;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author wyp
 * @since 2024-12-11
 */
@RestController
@RequestMapping("/tHoliday")
public class THolidayController  extends BaseWebAuthController {
    @Autowired
    private THolidayService tHolidayService;


    /**
     假期新增
     */
    @PostMapping("save")
    public AjaxResult save(@RequestBody THolidayVo tHolidayVo){
        //机构id
        tHolidayVo.setOrgId(Long.parseLong(loginDeptAuth()) );
        //当前登录人id
        tHolidayVo.setCreateUser(String.valueOf(getUserId()) );
        tHolidayVo.setCreateDate(LocalDateTime.now());
        tHolidayVo.setIsDelete("0");
        int i = tHolidayService.saveHolidayOrder(tHolidayVo);
        return AjaxResult.success(i);
    }

    /**
     假期修改
     */
    @PostMapping("update")
    public AjaxResult update(@RequestBody THolidayVo tHolidayVo){
        //机构id
        tHolidayVo.setOrgId(Long.parseLong(loginDeptAuth()) );
        //当前登录人id
        tHolidayVo.setUpdateUser(String.valueOf(getUserId()) );
        tHolidayVo.setUpdateDate(LocalDateTime.now());
        int i = tHolidayService.updateHolidayOrder(tHolidayVo);
        return AjaxResult.success(i);
    }

    /**
     假期删除
     */
    @PostMapping("delete")
    public AjaxResult delete(@RequestBody THolidayVo tHolidayVo){
        //机构id
//        tHolidayVo.setOrgId(Long.parseLong(loginDeptAuth()) );
        //当前登录人id
        tHolidayVo.setUpdateUser(String.valueOf(getUserId()) );
        tHolidayVo.setUpdateDate(LocalDateTime.now());
        tHolidayVo.setIsDelete("1");
        int i = tHolidayService.updateHolidayOrder(tHolidayVo);
        return AjaxResult.success(i);
    }

    /**
     假期列表
     */
    @GetMapping("list")
    public TableDataInfo list(THolidayVo tHolidayVo){
        startPage();
        //机构id
        tHolidayVo.setOrgId(Long.parseLong(loginDeptAuth()) );
        //当前登录人id
        tHolidayVo.setCreateUser(String.valueOf(getUserId()) );
//        tHolidayVo.setPOrgId(Long.parseLong(loginDeptParentAuth()) );
        List<THoliday> list = tHolidayService.holidayList(tHolidayVo);
        return getDataTable(list);
    }
}

